package com.mdx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdx.bean.RodentBean;
import com.mdx.service.IRodentService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 鼠害
 */
@RestController
@RequestMapping("rodent")
public class RodentController {
    @Resource
    private IRodentService rodentService;

    //显示所有鼠害信息
    @RequestMapping("findAllMouse")
    public IPage<RodentBean> findAllMouse(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                          @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return rodentService.findByName(pageNO,pageSize,null);
    }


    //添加新鼠害
    @RequestMapping("addRodent")
    public String addMouse(RodentBean rodentBean) {
        rodentService.save(rodentBean);
        return "ok";
    }


    //查看详细信息
    @RequestMapping("findById")
    public RodentBean findById(int rodentId) {
        return rodentService.getById(rodentId);
    }


    //模糊查询
    @RequestMapping("findName")
    public IPage<RodentBean> findName(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                     @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                     String rodentName) {
        return rodentService.findByName(pageNO,pageSize,rodentName);
    }
}
